package com.stylefeng.guns.checkoutdate;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by 60132 on 2018/10/7.
 */
public class dateCheck {
    public static void main(String [] args){
//        try {
//            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//            Calendar ca = Calendar.getInstance();
//            Date d = df.parse("2016-09-15");
//            ca.setTime(d);//设置当前时间
////             CalendarTest ct = new CalendarTest();
//            // ct.initHolidayList("2016-09-15");//初始节假日
//            // ct.initHolidayList("2016-09-16");//初始节假日
//            // ct.initHolidayList("2016-09-17");//初始节假日
//            // ct.initWeekendList("2016-09-18");//初始周末为工作日
////             boolean k = checkHoliday(ca);
//            // System.out.println(k);
//             }
//             catch ( Exception e) {
//            // TODO: handle exception
//            // 	System.out.println(e.getClass());
//            // e.printStackTrace();
//             }

        System.out.print(setTime("2018-10-07 16:01:00"));
    }

    public static String setTime(String time)  {

        Date date = null;
        try {
            date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar now = Calendar.getInstance();
        now.setTime(date);

                try {
                    Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(time);
                    Calendar now1 = Calendar.getInstance();
                    now1.setTime(date1);
                    now.set(now1.get(Calendar.YEAR),now1.get(Calendar.MONTH),now1.get(Calendar.DATE),now.get(Calendar.HOUR_OF_DAY),now.get(Calendar.MINUTE),now.get(Calendar.SECOND));
                } catch (Exception exception) {
                    exception.printStackTrace();
                }

        int minute = now.get(Calendar.MINUTE);
        if(minute>=0&&minute<15){
            now.set(now.get(Calendar.YEAR),now.get(Calendar.MONTH),now.get(Calendar.DATE),now.get(Calendar.HOUR_OF_DAY),00,00);
        }
        if(minute>=15&&minute<30){
            now.set(now.get(Calendar.YEAR),now.get(Calendar.MONTH),now.get(Calendar.DATE),now.get(Calendar.HOUR_OF_DAY),15,00);
        }
        if(minute>=30&&minute<45){
            now.set(now.get(Calendar.YEAR),now.get(Calendar.MONTH),now.get(Calendar.DATE),now.get(Calendar.HOUR_OF_DAY),30,00);
        }
        if(minute>=45&&minute<=59){
            now.set(now.get(Calendar.YEAR),now.get(Calendar.MONTH),now.get(Calendar.DATE),now.get(Calendar.HOUR_OF_DAY),45,00);
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now.getTime());
    }

}
